﻿<%@ Page Language="C#" AutoEventWireup="True" 
    CodeBehind="NodeList.aspx.cs" 
    Inherits="Medianamik.UI.NodeManagement.NodeList"
    MasterPageFile="../MasterPages/MedianamikModule.Master" %>
<%@ Import Namespace="Medianamik.Core" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" %>
<%@ Register TagPrefix="med" Namespace="Medianamik.UI.Controls" %>
<%@ Register TagPrefix="lock" Namespace="Medianamik.UI.Lock" %>

<%--Trace="true" TraceMode="SortByTime"--%>

<asp:Content ContentPlaceHolderID="HeaderContentHolder" runat="server">
</asp:Content>
<asp:Content ID="ContextMenuContent" ContentPlaceHolderID="ContextMenu" runat="server">
    <asp:UpdatePanel ID="addNodeUpdatePanel" runat="server" UpdateMode="Conditional"
        ChildrenAsTriggers="true">
        <ContentTemplate>
            <asp:HyperLink ID="lnkAddNode" runat="server" Target="TypeSelectorWindow" CssClass="Action BtAjouter"
                Text="<%$ Resources: Medianamik_ContentManagement, NewNodeButtonText %>" />
        </ContentTemplate>
    </asp:UpdatePanel>
    <a href="#" class="Action BtAnnuler-Inactif">
        <asp:Localize ID="Localize1" runat="server" Text="<%$ Resources: Medianamik_Global,Cancel %>"></asp:Localize></a>
</asp:Content>
<asp:Content ID="MainTreeView" ContentPlaceHolderID="VariableRightPanel" runat="server">
    <asp:UpdatePanel ID="updatePanel" UpdateMode="Always" runat="server">
        <ContentTemplate>
            <div class="BlocArbo">
                <telerik:RadTreeView ID="treeview" OnClientNodeClicked="ClientNodeClicked" OnNodeExpand="NodeExpand"
                    runat="server" ExpandDelay="0" Height="295" Width="222" EnableEmbeddedSkins="false"
                    Skin="Medianamik" OnClientMouseOver="onNodeMouseOver" OnClientMouseOut="onNodeMouseOut" />
                <asp:HiddenField ID="isNavigating" runat="server" Value="" />
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
<asp:Content ID="CenterContent" ContentPlaceHolderID="CenterContent" runat="server">
    <asp:ScriptManagerProxy ID="scriptManagerProxy" runat="server" OnNavigate="OnNavigate" />
    <asp:UpdatePanel ID="breadcrumbUpdatePanel" runat="server" UpdateMode="Conditional"
        ChildrenAsTriggers="true">
        <ContentTemplate>
            <med:BreadcrumbTrail ID="bctFilAriane" runat="server" CssClass="FilAriane" />
        </ContentTemplate>
    </asp:UpdatePanel>
    <asp:UpdatePanel ID="gridUpdatePanel" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <lock:LockInfoToolTip runat="server" ID="LockInfoTooltip" OnLockDeleted="LockInfoTooltip_LockDeleted" />
            <telerik:RadGrid runat="server" ID="grdNodes" EnableEmbeddedSkins="false" Skin="Medianamik"
                AllowPaging="false" AllowCustomPaging="false" AutoGenerateColumns="false" OnItemCommand="grdNodes_ItemCommand"
                OnNeedDataSource="grdNodes_NeedDataSource" OnItemDataBound="grdNodes_ItemDataBound"
                OnRowDrop="grdNodes_RowDrop" AllowMultiRowSelection="false" Width="100%">
                <MasterTableView DataKeyNames="ID">
                    <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" Position="TopAndBottom" />
                    <NoRecordsTemplate>
                        <asp:Literal ID="noRecords" runat="server" Text="<%$ Resources: Medianamik_ContentManagement, NoRecordsToDisplay %>" />
                    </NoRecordsTemplate>
                    <Columns>
                        <telerik:GridTemplateColumn>
                            <HeaderTemplate><asp:Literal ID="Literal1" runat="server" Text="<%$ Resources: Medianamik_ContentManagement, ContentNameColumn %>" /></HeaderTemplate>
                            <ItemStyle CssClass="DragCursor" />
                            <ItemTemplate>
                                <med:NodeTypeIcon runat="server" NodeTypeId='<%# Eval("NodeType.ID") %>' />
                                <p><asp:LinkButton ID="lnkNodeName" Text='<%# Eval("DisplayName") %>' CommandArgument='<%# Eval("ID") %>'
                                        runat="server" /><asp:Literal runat="server" Text='<%# " (" + Eval("ChildNodeCount") + ((int)Eval("ChildNodeCount") > 1 ? " items" : " item") + ")"   %>'
                                            Visible='<%# (int)Eval("ChildNodeCount") > 0 %>' /></p>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn HeaderStyle-Width="1%" HeaderText="Actions">
                            <HeaderStyle HorizontalAlign="Center" />
                            <ItemStyle CssClass="Actions" />
                            <ItemTemplate>
                                <table border="0" cellpadding="0" cellspacing="0" align="center">
                                    <tr>
                                        <td>
                                            <med:NodeActivationButton runat="server" ID="btnNodeActivation" IsActive='<%# Eval("DefaultInstance.IsActive") %>'
                                                DisabledImageUrl="/medianamik/images/Icones/Ico_ActifInactif.gif" OnCommand="OnNodeActivation" CommandArgument='<%#Eval("ID") %>'
                                                SecurityLevel="Update" NodeId='<%# Eval("ID") %>' />
                                        </td>
                                        <td>
                                            <med:LockButton ID="EditButton" SecurityLevel="Update" runat="server" NavigateUrl='<%# "Nodemanagement.aspx?" + DefaultParamNames.NodeID + "=" + Eval("ID") %>'
                                                NodeId='<%# Eval("ID") %>' title="<%$ Resources: Medianamik_Global, Action_EditTooltip %>"
                                                OnRequestFailed="LockLink_RequestFailed" />
                                        </td>
                                        <td>
                                            <med:DiffLink Enabled="true" runat="server" NodeId='<%# GetPreviewNodeId((Medianamik.Core.Node)Container.DataItem) %>'
                                                title="<%$ Resources: Medianamik_Global, Action_PreviewTooltip %>" ID="DiffLinkButton" />
                                        </td>
                                        <asp:PlaceHolder ID="SecurityPlaceHolder" runat="server">
                                            <td>
                                                <med:LockButton runat="server" SecurityLevel="Grant" ID="btnEditSecurity" Title="<%$ Resources: Medianamik_SecurityManagement, SecurityManagementTooltip %>"
                                                    NavigateUrl='<%# "securitymanagement.aspx?" + DefaultParamNames.NodeID + "=" + Eval("ID") %>' ImageUrl="/medianamik/images/Icones/Ico_SecuriteElement.png"
                                                    LockedOrDisabledImageUrl="/medianamik/images/Icones/Ico_SecuriteElementInactif.gif"
                                                    NodeId='<%# Eval("ID") %>' OnRequestFailed="LockLink_RequestFailed" />
                                            </td>
                                        </asp:PlaceHolder>
                                        <td>
                                            <med:LockButton ID="RevisionButton" Enabled="true" SecurityLevel="Update" runat="server"
                                                NavigateUrl='<%# "revisionmanagement.aspx?" + DefaultParamNames.NodeID + "=" + Eval("ID") %>' NodeId='<%# Eval("ID") %>'
                                                title="<%$ Resources: Medianamik_Global, Action_RevisionManagementTooltip %>"
                                                ImageUrl="/Medianamik/images/Icones/Ico_Revision.png" LockedOrDisabledImageUrl="/Medianamik/images/Icones/Ico_RevisionInactif.gif"
                                                OnRequestFailed="LockLink_RequestFailed" />
                                        </td>
                                        <td>
                                            <med:CheckLockButton ID="deleteNodeButton" runat="server" SecurityLevel="Delete" NodeId='<%# Eval("ID") %>'
                                                title="<%$ Resources: Medianamik_Global, Action_DeleteTooltip %>" ImageUrl="/medianamik/images/Icones/Ico_Supprimer.gif"
                                                LockedOrDisabledImageUrl="/medianamik/images/Icones/Ico_SupprimerInactif.gif"
                                                OnClientNotLocked='<%# String.Format("openDeleteNodeWindow(\"{0}\", \"{1}\")", Eval("ID"), CurrentEditionCulture.Name) %>'
                                                OnLocked="LockLink_RequestFailed" />
                                        </td>
                                    </tr>
                                </table>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                </MasterTableView>
                <ClientSettings AllowRowsDragDrop="True" EnableRowHoverStyle="true">
                    <Selecting AllowRowSelect="True" EnableDragToSelectRows="true" />
                    <ClientEvents OnRowDropping="onRowDropping" />
                </ClientSettings>
                <PagerStyle ShowPagerText="false" Mode="NumericPages" Position="TopAndBottom" />
            </telerik:RadGrid>
        </ContentTemplate>
    </asp:UpdatePanel>
    <br class="clearer" />
    <p class="Titre12pxBordure">
        <asp:Literal runat="server" Text="<%$ Resources: Medianamik_ContentManagement, CaptionLabel %>"></asp:Literal></p>
    <ul id="Legende">
        <li class="ElementBrouillon">
            <div>
                <span></span>
            </div>
            <asp:Literal runat="server" Text="<%$ Resources: Medianamik_ContentManagement, DraftContentCaption %>"></asp:Literal></li>
        <li class="Selection">
            <div>
                <span></span>
            </div>
            <asp:Literal runat="server" Text="<%$ Resources: Medianamik_ContentManagement, SelectedContentCaption %>"></asp:Literal></li>
        <li class="ElementNonTraduit">
            <div>
                <span></span>
            </div>
            <asp:Literal runat="server" Text="<%$ Resources: Medianamik_ContentManagement, NonTranslatedContentCaption %>"></asp:Literal></li>
    </ul>
    <br class="clearer" />
</asp:Content>
<asp:Content ID="ExternalContent" ContentPlaceHolderID="ExternalContentHolder" runat="server">
    <telerik:RadScriptBlock runat="server" ID="scriptBlock">

        <script type="text/javascript">
            //<![CDATA[
            
            var currentNode = null;
            var userMayMoveNode = <%= UserMayMoveNode ? "true" : "false" %>;
            
            function ClientNodeClicked(sender, eventArgs) {
                var node = eventArgs.get_node();
                if (node.get_expandMode() == 1) {
                    var isNavigating = $get('<%= isNavigating.ClientID %>');
                    isNavigating.value = node.get_value();
                    node.expand();
                }
                else {
                    __doPostBack('<%= isNavigating.ClientID %>', node.get_value());
                }
            }
            
            function onRowDropping(sender, args) {
                if (sender.get_id() == "<%=grdNodes.ClientID %>") {
                    var node = args.get_destinationHtmlElement();
                    if (!isChildOf('<%=grdNodes.ClientID %>', node) && !isChildOf('<%= treeview.ClientID %>', node)) {
                        args.set_cancel(true);
                    }
                    else if (currentNode) {
                        if(userMayMoveNode) {
                            var nodeId = currentNode.get_value();
                            if (currentNode.get_enabled()) {
                                //Store the value of the node on which the mouse is over
                                if(confirm('<%= Translator.TranslateJS("Medianamik_ContentManagement", "ConfirmMoveNodeText") %>')) {
                                $get("<%= TreeNodeId.ClientID %>").value = nodeId;
                                }
                                else {
                                    args.set_cancel(true);
                                }
                            }
                            else {
                                args.set_cancel(true);
                                alert('<%= Translator.TranslateJS("Medianamik_ContentManagement", "AlertCannotMoveNode") %>');
                            }
                        }
                        else {
                            alert('<%= Translator.TranslateJS("Medianamik_ContentManagement", "AlertNotAllowedToMoveNode") %>');
        
                        }
                    }
                }
            }

            function isChildOf(parentId, element) {
                while (element) {
                    if (element.id && element.id.indexOf(parentId) > -1) {
                        return true;
                    }
                    element = element.parentNode;
                }
                return false;
            }

            function onNodeMouseOver(sender, args) {
                if(userMayMoveNode){
                    currentNode = args.get_node();
                }
            }

            function onNodeMouseOut(sender, args) {
                if(userMayMoveNode){
                    currentNode = null;
                }
            }
            
             <%= Medianamik.UI.Utility.GetDeleteElementScript(RadAjaxManager.GetCurrent(Page).ClientID,
                Medianamik.Core.Pages.DeleteElementWindow, CurrentEditionCulture.Name, 
                false, CurrentEditionCulture.Name == "") %>


            <%= Medianamik.UI.Utility.GetCultureSelectedScript("/medianamik/contentmanagement/nodemanagement.aspx", 
                false, DefaultParamNames.NodeID, "") %>

            <%= Medianamik.UI.Utility.GetTypeSelectedScript("/medianamik/contentmanagement/nodemanagement.aspx", 
                false, DefaultParamNames.ParentNodeID, DefaultParamNames.TypeID, "") %>

            //]]>
        </script>

    </telerik:RadScriptBlock>
    <asp:HiddenField runat="server" ID="TreeNodeId" />
</asp:Content>
